import React from 'react';

const EventForm = ({ onSave, onCancel, selectedDate }) => {
  const [formData, setFormData] = React.useState({
    title: '',
    date: selectedDate.toISOString().split('T')[0],
    startTime: '09:00',
    endTime: '10:00'
  });

  const handleSubmit = (e) => {
    e.preventDefault();
    onSave({
      ...formData,
      date: formData.date,
    });
    setFormData({
      title: '',
      date: selectedDate.toISOString().split('T')[0],
      startTime: '09:00',
      endTime: '10:00'
    });
  };

  return (
    <div className="event-form">
      <h3>{formData.id ? '编辑日程' : '添加日程'}</h3>
      <form onSubmit={handleSubmit}>
        <div className="form-item">
          <input
            type="text"
            value={formData.title}
            onChange={(e) => setFormData({...formData, title: e.target.value})}
            placeholder="事件标题"
            required
          />
        </div>
        <div className="form-item">
          <label>日期：</label>
          <input
            type="date"
            value={formData.date}
            onChange={(e) => setFormData({...formData, date: e.target.value})}
            required
          />
        </div>
        <div className="form-item">
          <label>开始时间：</label>
          <input
            type="time"
            value={formData.startTime}
            onChange={(e) => setFormData({...formData, startTime: e.target.value})}
            required
          />
        </div>
        <div className="form-item">
          <label>结束时间：</label>
          <input
            type="time"
            value={formData.endTime}
            onChange={(e) => setFormData({...formData, endTime: e.target.value})}
            required
          />
        </div>
        <div className="form-actions">
          <button type="button" onClick={onCancel} className="cancel-btn">
            取消
          </button>
          <button type="submit" className="save-btn">
            保存
          </button>
        </div>
      </form>
    </div>
  );
};

export default EventForm; 